#include <iostream>
using std::cout;
using std::endl;

class Point
{
public:
    Point(int x,int y = 0)
    : _ix(x)
    , _iy(y)
    {
        cout << "Point(int,int)" << endl;
    }

    ~Point(){
        cout << "~Point()" << endl;
    }

    Point(const Point & rhs)
    : _ix(rhs._ix)
    , _iy(rhs._iy)
    {
        cout << "Point(const Point&)" << endl;
    }

    Point & operator=(const Point & rhs){
        cout << "赋值运算符函数" << endl;
        _ix = rhs._ix;
        _iy = rhs._iy;
        return *this;//返回本对象（调用赋值运算符函数的对象）
    }


    //this指针记录的是本次调用成员函数的对象的地址
    //在成员函数中通过this指针访问“本对象”的成员
    //this指针的类型：Point * const this
    //this指针不要显式地在参数列表中写出
    //编译器会默认地将this指针加入，作为成员函数的第一个参数
    void print(){
        /* &this;//error */
        /* this = new Point(1,2);//error */
        /* this->_ix = 100;//ok */
        cout << "(" << this->_ix
            << "," << this->_iy
            << ")" << endl;
    }
private:
    int _ix = 10;
    int _iy = 10;
};


void test0(){
    int x = 1;
    int y = 2;
    cout << &x << endl;
    //赋值操作表达式的返回值应该是左操作数本身
    cout << &(x = y) << endl;

    Point pt(10,8);
    Point pt2(4,5);
    //自定义类型的对象也可以利用赋值号进行赋值操作
    pt = pt2;
    pt.operator=(pt2);//本质
    pt.print();
    pt2.print();

    pt2 = pt;
    pt2.operator=(pt);
}

int main(void){
    test0();
    return 0;
}
